<!DOCTYPE html>
<html>
	<head>
		<title>Adding new group methods</title>
		<link rel="stylesheet" href="../../codebase/webix/webix.css" type="text/css" charset="utf-8">
		<script src="../../codebase/webix/webix.js" type="text/javascript" charset="utf-8"></script>
		<link rel="stylesheet" href="../../codebase//pivot.css" type="text/css" charset="utf-8">
		<script src="../../codebase/pivot.js" type="text/javascript" charset="utf-8"></script>

		<link rel="stylesheet" href="../common/samples.css" type="text/css" charset="utf-8">
		<script src="../common/testdata.js" type="text/javascript" charset="utf-8"></script>
		<style type="text/css">
			html, body {
				width: 100%;
				height: 100%;
				padding: 0;
				margin: 0;
			}
		</style>
	</head>
	<body>
		<div class='header_comment'>Adding new group methods</div>
		<div id="testA"></div>

		<script type="text/javascript" charset="utf-8">
			webix.ready(function(){
				var chart = webix.ui({
					container:"testA",
					id:"pivot",
					view:"pivot-chart",
					height:300,
					width:800,
					structure:{
						groupBy: "year",
						values: [{name:"balance", operation:"sum", color: "#eed236"},{name:"balance", operation:"average", color: "#36abee"}],
						filters:[{name:"name", type:"select"}]
					},
					groupMethods:{
						average: function(template, data){
							data = data || this;
							var summ = 0;
							for (var i = 0; i < data.length; i++)
								summ+= template(data[i])*1;
							return data.length?summ/data.length:0;
						}
					},
					data:pivot_dataset
				});
			});
		</script>
	</body>
</html>